Imports System.Runtime.Serialization

Namespace Core.Data.Preferences
    <Serializable()> _
        Public Class MyPreferences
        Implements ISerializable

        Public Const FileName As String = "my.preferences"

        Private zAnnounceFrequency As Double
        Private zAnnouncePort As UInt16
        Private zConnectionPort As UInt16

        Public MainForm_Visible As Boolean
        Public MainForm_WindowState As Integer
        Public MainForm_Width As Integer
        Public MainForm_Height As Integer
        Public MainForm_Top As Integer
        Public MainForm_Left As Integer

        Public Property AnnounceFrequency() As Double
            Get
                Return zAnnounceFrequency
            End Get

            Set(ByVal value As Double)
                zAnnounceFrequency = value
            End Set
        End Property

        Public Property AnnouncePort() As UInt16
            Get
                Return zAnnouncePort
            End Get

            Set(ByVal value As UInt16)
                zAnnouncePort = value
            End Set
        End Property

        Public Property ConnectionPort() As UInt16
            Get
                Return zConnectionPort
            End Get

            Set(ByVal value As UInt16)
                zConnectionPort = value
            End Set
        End Property

        Public Sub New() ' parameterless constructor must exist for ISerializable support

        End Sub

        Public Sub New(ByVal pB_Default As Boolean)
            If pB_Default Then
                zAnnounceFrequency = 1000
                zAnnouncePort = 50005
                zConnectionPort = zAnnouncePort
            End If
        End Sub

#Region " ISerializable Support "
        Private Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)
            zAnnounceFrequency = info.GetDouble("zAnnounceFrequency")
            zAnnouncePort = info.GetUInt16("zAnnouncePort")
            zConnectionPort = info.GetUInt16("zConnectionPort")

            MainForm_Visible = info.GetBoolean("MainForm_Visible")
            MainForm_WindowState = info.GetInt32("MainForm_WindowState")
            MainForm_Width = info.GetInt32("MainForm_Width")
            MainForm_Height = info.GetInt32("MainForm_Height")
            MainForm_Top = info.GetInt32("MainForm_Top")
            MainForm_Left = info.GetInt32("MainForm_Left")
        End Sub

        Public Overridable Sub GetObjectData(ByVal info As System.Runtime.Serialization.SerializationInfo, ByVal context As System.Runtime.Serialization.StreamingContext) Implements System.Runtime.Serialization.ISerializable.GetObjectData
            info.AddValue("zAnnounceFrequency", zAnnounceFrequency)
            info.AddValue("zAnnouncePort", zAnnouncePort)
            info.AddValue("zConnectionPort", zConnectionPort)

            info.AddValue("MainForm_Visible", MainForm_Visible)
            info.AddValue("MainForm_WindowState", MainForm_WindowState)
            info.AddValue("MainForm_Width", MainForm_Width)
            info.AddValue("MainForm_Height", MainForm_Height)
            info.AddValue("MainForm_Top", MainForm_Top)
            info.AddValue("MainForm_Left", MainForm_Left)
        End Sub
#End Region
    End Class
End Namespace
